Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / network / src / jvmTest / kotlin / org / meshtastic / core / network / repository / JvmServiceDiscoveryTest.kt

Displaying Raw • Download

core/network/src/jvmTest/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscoveryTest.kt 0a44b948ec0573dc62ec68c19e46e62d40fcd1a3 (0a44b948) Text, 2.40 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.network.repository

Tff7b72import T7ee787app.cash.turbine.test
Tff7b72import T7ee787kotlinx.coroutines.test.UnconfinedTestDispatcher
Tff7b72import T7ee787kotlinx.coroutines.test.runTest
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertNotNull
Tff7b72import T7ee787kotlin.test.assertTrue

Tff7b72class T56d364JvmServiceDiscoveryTest Tb4b4b4{

Tff7b72private Tff7b72val Te6edf3testDispatchers Tff7b72=
Te6edf3UnconfinedTestDispatcherTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3let Tb4b4b4{ Te6edf3dispatcher Tff7b72-Tff7b72>
Te6edf3CoroutineDispatchersTb4b4b4(Te6edf3io Tff7b72= Te6edf3dispatcherTb4b4b4, Te6edf3main Tff7b72= Te6edf3dispatcherTb4b4b4, Te6edf3default Tff7b72= Te6edf3dispatcherTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`resolvedServices emits initial empty list immediately`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Tff7b72val Te6edf3discovery Tff7b72= Te6edf3JvmServiceDiscoveryTb4b4b4(Te6edf3testDispatchersTb4b4b4)
Te6edf3discoveryTb4b4b4.Te6edf3resolvedServicesTb4b4b4.Te6edf3test Tb4b4b4{
Tff7b72val Te6edf3first Tff7b72= Te6edf3awaitItemTb4b4b4(Tb4b4b4)
Te6edf3assertNotNullTb4b4b4(Te6edf3firstTb4b4b4, Ta5d6ff"Ta5d6ffFirst emission should not be nullTa5d6ff"Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3firstTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4, Ta5d6ff"Ta5d6ffFirst emission should be an empty listTa5d6ff"Tb4b4b4)
Te6edf3cancelAndIgnoreRemainingEventsTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`findLanAddress returns non-loopback address or null`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3address Tff7b72= Te6edf3JvmServiceDiscoveryTb4b4b4.Te6edf3findLanAddressTb4b4b4(Tb4b4b4)
T8b949e// On CI machines there may be no LAN interface, so null is acceptable
Tff7b72if Tb4b4b4(Te6edf3address Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3assertTrueTb4b4b4(Tff7b72!Te6edf3addressTb4b4b4.Te6edf3isLoopbackAddressTb4b4b4, Ta5d6ff"Ta5d6ffAddress should not be loopbackTa5d6ff"Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3address Tff7b72is Te6edf3javaTb4b4b4.Te6edf3netTb4b4b4.Te6edf3Inet4AddressTb4b4b4, Ta5d6ff"Ta5d6ffAddress should be IPv4Ta5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`findLanAddress does not throw`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Ensure the method handles exceptions gracefully
Tff7b72val Te6edf3result Tff7b72= Te6edf3runCatching Tb4b4b4{ Te6edf3JvmServiceDiscoveryTb4b4b4.Te6edf3findLanAddressTb4b4b4(Tb4b4b4) Tb4b4b4}
Te6edf3assertTrueTb4b4b4(Te6edf3resultTb4b4b4.Te6edf3isSuccessTb4b4b4, Ta5d6ff"Ta5d6fffindLanAddress should not throw: Tffd700${Te6edf3resultTb4b4b4.Te6edf3exceptionOrNullTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s